home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / _truncdf.cpp < prev    next >
Text File  |  1993-06-17  |  3KB  |  140 lines

  1. | not needed with -__M68881__
  2.  
  3. #ifndef    __M68881__
  4.     .text
  5.     .even
  6.     .globl    __truncdfsf2, ___truncdfsf2
  7.  
  8. __truncdfsf2:
  9. ___truncdfsf2:
  10. # ifdef    sfp004
  11.  
  12. | double float to single float conversion routine
  13. | oflow checking is omitted. The ''881 returns a signed infinity.
  14. |
  15. | Written by M.Ritzert
  16. | 5.10.90
  17. | ritzert@dfg.dbp.de
  18. |
  19.  
  20. | addresses of the 68881 data port. This choice is fastest when much data is
  21. | transferred between the two processors.
  22.  
  23. comm =     -6
  24. resp =    -16
  25. zahl =      0
  26.  
  27. | waiting loop ...
  28. |
  29. | wait:
  30. | ww:    cmpiw    #0x8900,a1@(resp)
  31. |     beq    ww
  32. | is coded directly by
  33. |    .long    0x0c688900, 0xfff067f8
  34.  
  35.     lea    0xfffffa50:w,a0
  36.     movew    #0x5400,a0@(comm)    | load double to  fp0
  37.     cmpiw    #0x8900,a0@(resp)    | check
  38.     movel    a7@(4),a0@        | push arguments
  39.     movel    a7@(8),a0@        |
  40.     movew    #0x6400,a0@(comm)    | result (real) to d0
  41.     .long    0x0c688900, 0xfff067f8
  42.     movel    a0@,d0
  43.     rts
  44.  
  45. # else    sfp004
  46.  
  47. | double float to single float conversion routine
  48. |
  49. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  50. | Based on a 80x86 floating point packet from comp.os.minix, written by P.Housel
  51. |
  52. | Revision 1.2.2 michal 05-93: (ntomczak@vm.ucs.ualberta.ca)
  53. |  + corrected bug in setting sign of returned Inf
  54. |  + code cleanup
  55. |
  56. | patched by Olaf Flebbe (flebbe@tat.physik.uni-tuebingen.de)
  57. |
  58. | Revision 1.2.1 olaf 12-92 :
  59. |  + added support for Inf and NaN.
  60. |
  61. | Revision 1.2, kub 01-90 :
  62. | added support for denormalized numbers
  63. |
  64. | Revision 1.1, kub 12-89 :
  65. | Ported over to 68k assembler
  66. |
  67. | Revision 1.0:
  68. | original 8088 code from P.S.Housel
  69.  
  70. BIAS4    =    0x7F-1
  71. BIAS8    =    0x3FF-1
  72.  
  73.     moveml    sp@(4),d0-d1    | get number
  74.     moveml    d2-d5,sp@-    | save regs
  75.  
  76.     movel    d0,d4        | save for norm_df
  77.     swap    d0        | extract exponent
  78.     movew    d0,d2        | extract sign
  79.     bclr    #15,d0        | kill sign bit
  80.     lsrw    #4,d0
  81.     andl    #0x0fffff,d4    | remove exponent from mantissa
  82. |
  83. |
  84. |
  85.     cmpw    #0x7ff,d0
  86.     bne    nospec
  87.     orl    d4,d1
  88.     bne    retnan
  89.     movel   #0xff00000,d0
  90.     lslw    #1,d2
  91.     roxrl    #1,d0
  92. return:    moveml    sp@+,d2-d5
  93.     rts
  94. retnan:    moveq    #-1,d0
  95.     lsrl    #1,d0        | #0x7fffffff -> d0
  96.     bra    return
  97.  
  98. | Should we really return SNaN, which has a sign bit set accordingly??
  99. | if yes, then the following code can be used instead -- mj
  100. |
  101. |    cmpw    #0x7ff,d0
  102. |    bne    nospec
  103. |    orl    d4,d1
  104. |    bne    retnan
  105. |    movel   #0xff00000,d0
  106. |return:
  107. |    lslw    #1,d2        | set X bit
  108. |    roxrl    #1,d0        | roll in sign bit
  109. |    moveml    sp@+,d2-d5
  110. |    rts
  111. |retnan:    moveq    #-1,d0
  112. |    bra    return
  113.  
  114. nospec:    movel    d1,d5
  115.     bset    #20,d4        | restore implied leading "1"
  116.     tstw    d0        | check for zero exponent - no leading "1"
  117.     bne    1f        | for denormalized numbers
  118.     bclr    #20,d4        | ... so do not do it but instead
  119.     addw    #1,d0        | "normalize" exponent
  120. 1:
  121.     addw    #BIAS4-BIAS8,d0    | adjust bias
  122.  
  123.     addl    d5,d5        | shift up to realign mantissa for floats
  124.     addxl    d4,d4
  125.     addl    d5,d5
  126.     addxl    d4,d4
  127.     addl    d5,d5
  128.     addxl    d4,d4
  129.  
  130.     movel    d5,d1        | set rounding bits
  131.     roll    #8,d1
  132.     andl    #0x00ffffff,d5    | check to see if sticky bit should be set
  133.     beq    2f
  134.     orb    #1,d1        | set sticky bit
  135. 2:
  136.     jmp    norm_sf        | (leave regs on stack for norm_sf)
  137.  
  138. # endif    sfp004
  139. #endif    __M68881__
  140.